<template>
  <div class>


      <tableComponents
        :isShow="false"
        @toAdd='openDio("saveadd")'
        :isHaveExport="false"
        :isShowBottom="false"
      >
        <template v-slot:table>
          <el-table
            ref="multipleTable"
            header-row-class-name="head_color"
            :data="list"
            v-loading="loading"
            stripe
            tooltip-effect="dark"
            style="width: 99.9%"
          >
            <el-table-column label min-width="20">
              <template></template>
            </el-table-column>

<!--            <el-table-column label="每月团队业绩" min-width="200">-->
<!--              <template slot-scope="scope">{{ scope.row.money |keepTwoNum }}</template>-->
<!--            </el-table-column>-->

            <el-table-column label="奖励金额千分比" min-width="200">
              <template slot-scope="scope">{{ scope.row.reward }}‰</template>
            </el-table-column>

            <el-table-column label="操作" min-width="60">
              <template slot-scope="scope">
                <el-button
                  :loading="$store.state.isLoading"
                  size="mini"
                  @click="showEditDialog(scope.$index,scope.row,'saveedit')"
                >编辑</el-button>
                <el-button
                  :loading="$store.state.isLoading"
                  size="mini"
                  @click="deleteNew(scope.$index, scope.row.id)"
                  type="danger"
                >删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </tableComponents>

      <el-dialog
        :title="mytitle"
        :modal-append-to-body="false"
        :visible.sync="dialogFormVisible"
        v-if="dialogFormVisible"
        :close-on-click-modal="false"
        class="tl size_13"
        width="800px"
      >
        <el-form :model="data" :rules="dataYZ" ref="data" label-width="120px">
<!--          <el-form-item label="每月团队业绩" prop="money">-->
<!--            <el-col :span="12">-->
<!--              <el-input-->
<!--                v-Int-->
<!--                placeholder="请输入每月团队业绩"-->
<!--                v-model="data.money"-->
<!--                clearable-->
<!--              ></el-input>-->
<!--            </el-col>-->
<!--          </el-form-item>-->

          <el-form-item label="奖励金额千分比" prop="reward">
            <el-col :span="12">
              <el-input
                v-enterNumber
                placeholder="请输入奖励金额千分比"
                v-model="data.reward"
                clearable
              >
                <template slot="append">‰</template>
              </el-input>
            </el-col>
          </el-form-item>

          <el-form-item>
            <el-button
              :loading="$store.state.isLoading"
              size="mini"
              type="primary"
              @click="addSave('data')"
            >确定</el-button>
          </el-form-item>
        </el-form>
      </el-dialog>
  </div>
</template>
<script>
import HeadTitle from "@/components/currency/HeadTitle.vue";
export default {
  data() {
    return {
      loading: false,
      show: false,
      myshow: false,
      updatelock: false,
      mytitle: "",
      list: [],
      adminId: "",
      dialogFormVisible: false,

      uddateIndex: "",
      options: [
        {
          value: "",
          label: ""
        }
      ],
      value: "",
      data: {
        reward: "",
        money: ""
      },
      dataYZ: {
        money: [
          // { required: true, message: "请输入每月团队业绩", trigger: "blur" }
        ],
        reward: [
          { required: true, message: "请输入奖励金额千分比", trigger: "blur" }
        ]
      }
    };
  },
  components: {
    HeadTitle
  },
  methods: {
    openDio(str) {
      this.dialogFormVisible = true;
      this.showImg = false;
      this.updatelock = false;

      this.data = {
        reward: "",
        money: ""
      };
      this.data.action = str;
      this.mytitle = "添加";
    },
    getNewsAll() {
      this.loading = true;
      var data = {};
      data.cltrlclass = "team";
      data.action = "lists";
      this.$api.getYc.getTeamList(data).then(res => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
        this.loading = false;
      });
    },
    deleteNew(index, id) {
      this.$swal({
        title: "您确定要删除这条信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思"
      }).then(willDelete => {
        if (willDelete.value) {
          var params = {};
          params.id = id;
          this.$api.getYc.delTeam(params).then(res => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", "您已经删除了这条信息。", "success");
              this.list.splice(index, 1);
            } else {
              this.$swal("删除失败！", res.result.data, "success");
            }
          });
        } else if (willDelete.dismiss == "cancel") {
          this.$swal("已取消", "您取消了删除操作", "error");
        }
      });
    },

    showEditDialog(index, row, str) {
      this.dialogFormVisible = true;
      row.money = this.$fnc.toFixedZ(row.money);
      this.data = row;
      this.data.action = str;
      this.mytitle = "编辑";
      this.updatelock = true;

      console.log(row);
    },
    addSave(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.dialogFormVisible = false;
          var params = {};
          params = this.data;
          params.cltrlclass = "team";
          if (params.id) {
            this.$api.getYc.saveeditTeam(params).then(res => {
              if (res.data.code == 200 && res.data.result != null) {
                this.$fnc.alertSuccess({ text: "修改成功" }); //成功弹出框
                this.dialogFormVisible = false;
                this.list[this.uddateIndex] = this.data;
              } else {
                this.$fnc.alertError(res.data.code_desc, res.data.result); //失败弹出框
              }
            });
          } else {
            this.$api.getYc.addTeam(params).then(res => {
              if (res.data.code == 200 && res.data.result != null) {
                this.$fnc.alertSuccess({ text: "添加成功" }); //成功弹出框
                this.dialogFormVisible = false;
                this.getNewsAll();
              } else {
                this.$fnc.alertError(res.data.code_desc, res.data.result); //失败弹出框
              }
            });
          }
        } else {
          return false;
        }
      });
    }
  },

  created() {
    this.getNewsAll();
  },
  computed: {},

  watch: {}
};
</script>
